/**
*      author: Y_Yao
*      created: 2024-10-25 19:36:52
**/

#include<bits/stdc++.h>

using namespace std;
#define int LL
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int a[N];
int n;

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }

    for(int i = 2;i <= n / 2;i++)
    {
        int no = a[i] == a[i-1] ? 1 : 0;
        no += a[n - i + 1] == a[n - i + 2] ? 1 : 0;
        int yes = a[n - i + 1] == a[i - 1] ? 1 : 0;
        yes += a[i] == a[n - i + 2] ? 1 : 0;

        if(yes < no)
        {
            swap(a[i],a[n - i + 1]);
        }
    }

    int ret = 0;
    for(int i = 1;i < n;i++)
    {
        if(a[i] == a[i + 1]) ret++;
    }
    cout << ret << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}